(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:H5hddetailCtrl
     * @description
     * # H5hddetailCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('H5hddetailCtrl', H5hddetailCtrl);

    H5hddetailCtrl.$inject = ['$scope', 'dataService', 'helper', '$location', '$timeout', 'moment', '$rootScope'];

    function H5hddetailCtrl($scope, dataService, helper, $location, $timeout, moment, $rootScope) {

        $scope.listAction = function() {
            $scope.xtotal = 0;
            $scope.Status = 1;
            $scope.h5hd_id = $location.search().h5hd_id;
            $scope.title = $location.search().title;
            if ($scope.h5hd_id) {
                $scope.getList();
            }

        }

        //获取列表
        $scope.getList = function(pageNo) {


            var query = {
                content: {
                    page_no: pageNo,
                    page_size: $scope.page_Size ? $scope.page_Size : 10,
                    store_id: $rootScope.store_id,
                    h5hd_id: $scope.h5hd_id
                }
            };
            if ($scope.code) {
                query.content.code = $scope.code;
            }
            if ($scope.phone) {
                query.content.phone = $scope.phone;
            }
            if ($scope.Status) {
                query.content.status = $scope.Status;
            }

            dataService.h5hddetailGet(query).then(function(list) {
                if (list && list.h5hd_detail_list) {

                    $scope.h5hd_detail_list = list.h5hd_detail_list;

                    $scope.total = list.detail_count;
                }
            });
        }


        //活动添加
        $scope.upstatus = function(id) {

            if (id) {

                var data = {
                    content: {
                        "h5hd_details_id": id,
                        "status": 2,
                    }
                }
                console.error("$scope.h5hd", data);
                helper.myConfirm('确认核销使用？', function() {
                    dataService.h5hddetailUpdate(data).then(function(result) {
                        if (result.h5hd_details_id) {
                            helper.myAlert("success");
                            $scope.getList();
                        } else {
                            helper.myAlert(result.Msg);
                        }
                    });
                });

            }
        }

        $scope.delete = function(appid) {
            dataService.isvWxappDelete(appid).then(function(result) {
                console.log("------", result);
                if (result.Msg) {
                    helper.myAlert("错误：" + result.Msg);
                } else {
                    $scope.getList();
                }
            });
        }


    }
})();